package com.neusoft.yuejian26.yuejian_26.Adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.neusoft.yuejian26.yuejian_26.Activity.ActSimpActivity;
import com.neusoft.yuejian26.yuejian_26.Activity.ShareSimpActivity;
import com.neusoft.yuejian26.yuejian_26.Bean.ClubSimpbean;
import com.neusoft.yuejian26.yuejian_26.Bean.MySharebean;
import com.neusoft.yuejian26.yuejian_26.Bean.Userbean;
import com.neusoft.yuejian26.yuejian_26.R;
import com.neusoft.yuejian26.yuejian_26.model.ClubModel;
import com.neusoft.yuejian26.yuejian_26.model.UserModel;
import com.neusoft.yuejian26.yuejian_26.network.RetrofitCallback;
import com.squareup.picasso.Picasso;

import java.util.List;

import retrofit2.Call;

/**
 * Created by Administrator on 2017/10/30 0030.
 */

public class MyShareAdapter  extends XRecyclerView.Adapter<XRecyclerView.ViewHolder> {
    private Context mContext;
    protected List mDataList;
    private LayoutInflater mlayoutInflater;
    public MyShareAdapter(Context mContext, List<MySharebean> mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mlayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public XRecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mlayoutInflater.from(parent.getContext()).inflate(R.layout.mysharelist_item, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(XRecyclerView.ViewHolder holder, int position) {
        final MySharebean entity = (MySharebean) mDataList.get(position);
        if (null == entity)
            return;
        MyShareAdapter.ViewHolder viewHolder = (MyShareAdapter.ViewHolder) holder;
        viewHolder.myshare_list_content.setText(entity.getPtext());
         viewHolder.myshare_list_uname.setText(entity.getUname());
        Picasso.with(mContext)
                .load("http://115.159.93.244/new18yuejian/Public/upload/"+entity.getUserpic())
                .into(viewHolder.myshare_list_upic);
        Picasso.with(mContext)
                .load("http://115.159.93.244/new18yuejian/Public/upload/"+entity.getPostfile())
                .into(viewHolder.myshare_list_pic);
        viewHolder.myShareitem.setOnClickListener(new View.OnClickListener(){
            @Override
            public  void onClick(View v){
                Intent intent= new Intent(mContext, ShareSimpActivity.class);
                Bundle bundle= new Bundle();
                bundle.putString("uiid",entity.getUid());
                bundle.putString("pid",entity.getPid());
                intent.putExtras(bundle);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    private class ViewHolder extends XRecyclerView.ViewHolder {
        TextView myshare_list_uname,myshare_list_content;
        ImageView myshare_list_upic,myshare_list_pic;
        CardView myShareitem;
        public ViewHolder(View v) {
            super(v);
            myshare_list_uname = (TextView) v.findViewById(R.id.myshare_list_uname);
            myshare_list_content= (TextView) v.findViewById(R.id.myshare_list_content);
            myshare_list_upic = (ImageView) v.findViewById(R.id.myshare_list_upic);
            myshare_list_pic = (ImageView) v.findViewById(R.id.myshare_list_pic);
            myShareitem = (CardView) v.findViewById(R.id.myshare_item_card);

        }
    }
}
